package com.taoyibao.hongcanting.ui.restaurant.area;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.BaseRelativeLayout;
import com.taoyibao.hongcanting.dialog.DialogMapTable;
import com.taoyibao.hongcanting.event.EventCurrentPage;
import com.taoyibao.hongcanting.widget.BottomBarItem;

import org.greenrobot.eventbus.EventBus;

/**
 * @author TangAnna
 * @description:
 * @date :${DATA} 17:03
 */
public class MainBottomArea extends BaseRelativeLayout implements View.OnClickListener {


    private DialogMapTable mDialogMapTable;
    private BottomBarItem mItemHome;
    private BottomBarItem mItemRest;
    private BottomBarItem mItemMine;

    public MainBottomArea(Context context) {
        super(context);
    }

    public MainBottomArea(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MainBottomArea(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initView(Context context, AttributeSet attrs, int defStyleAttr) {
        mItemHome = findViewById(R.id.bottom_home);
        mItemRest = findViewById(R.id.bottom_restaurant);
        mItemMine = findViewById(R.id.bottom_mine);
        findViewById(R.id.bottom_entertainment).setOnClickListener(this);
        mItemHome.setOnClickListener(this);
        mItemRest.setOnClickListener(this);
        mItemMine.setOnClickListener(this);


    }

    @Override
    public void setData(Object data) {

    }

    @Override
    protected int bindLayout() {
        return R.layout.area_main_bottom;
    }

    public void setChange(BottomBarItem bottomBarItem, int position) {
        bottomBarItem.setStatus(true);
        EventCurrentPage eventCurrentPage = new EventCurrentPage();
        eventCurrentPage.target = "MainActivity";
        eventCurrentPage.mCurrentPage = position;
        EventBus.getDefault().post(eventCurrentPage);
        if (mBottomSelectedListener != null) {
            mBottomSelectedListener.Selected(bottomBarItem, position);
        }
    }

    private BottomSelectedListener mBottomSelectedListener;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bottom_home:
                setChange(mItemHome, 0);
                break;
            case R.id.bottom_restaurant:
                setChange(mItemRest, 1);
                break;
            case R.id.bottom_entertainment:
                setChange(mItemMine, 2);
                break;
            case R.id.bottom_mine:
                setChange(mItemMine, 3);
                break;
        }
    }

    public interface BottomSelectedListener {
        void Selected(BottomBarItem bottomBarItem, int position);
    }

    public void setBottomSelectedListener(BottomSelectedListener bottomSelectedListener) {
        mBottomSelectedListener = bottomSelectedListener;
    }
}
